#include "types.h"
#include "stat.h"
#include "user.h"
#include "fcntl.h"

int main() {
    int fd1, fd2;
    fd1 = open("testfile.txt", O_RDWR | O_CREATE);
    if (fd1 < 0) {
        printf(1, "open failed\n");
        exit();
    }

    fd2 = dup2(fd1, 1); // 将标准输出重定向到 fd1
    if (fd2 < 0) {
        printf(1, "dup2 failed\n");
        close(fd1);
        exit();
    }

    printf(1, "This should be written to testfile.txt\n");

    close(fd1);
    close(fd2);
    exit();
}
